//
//  BSWindow.m
//  BaiSi
//
//  Created by Sycamore on 16/5/9.
//  Copyright © 2016年 Sycamore. All rights reserved.
//

#import "BSWindow.h"

@interface BSWindow ()



@end


@implementation BSWindow
//使用全局变量就能保证window在整个程序运行过程中都不会释放
BSWindow *_statuswindow;


+ (void)show
{
    //创建一个透明的window,覆盖在状态栏上面
    BSWindow *statusWindow = [[self alloc]initWithFrame:[UIApplication sharedApplication].statusBarFrame];
    
    statusWindow.rootViewController = [[UIViewController alloc]init];
    statusWindow.hidden = NO;
    statusWindow.backgroundColor = [UIColor clearColor];
    statusWindow.windowLevel = UIWindowLevelAlert;
    _statuswindow= statusWindow;

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //找到当前正在显示的那个tableView,让其滚动到最顶部,需要使用递归
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [self getSubViewFromSuperView:window];
}

- (void)getSubViewFromSuperView:(UIView *)view
{
    for (UIView *subView in view.subviews) {
        
        //一直遍历到tableView
        if ([subView isKindOfClass:[UITableView class]]) {
            UITableView *tableView = (UITableView *)subView;
            [tableView setContentOffset:CGPointMake(0, -108) animated:YES];
            
            //退出递归
            return;
            
        }
        
        //一直往下遍历
        [self getSubViewFromSuperView:subView];

    }
}


@end
